package com.lagou.demo.controller;

import com.lagou.demo.service.IDemoService;
import com.lagou.edu.mvcframework.annotations.LagouAutowired;
import com.lagou.edu.mvcframework.annotations.LagouController;
import com.lagou.edu.mvcframework.annotations.LagouRequestMapping;
import com.lagou.edu.mvcframework.annotations.LagouSecurity;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@LagouController
@LagouRequestMapping("/movie")
@LagouSecurity(auths={"father","mother","son"})
public class MovieController {


    @LagouAutowired
    private IDemoService demoService;

    /**
     * URL: /movie/common?username=father
     * @param request
     * @param response
     * @param username
     * @return
     */
    @LagouRequestMapping("/common")
    public String methodWithoutAuth(HttpServletRequest request, HttpServletResponse response,String username) throws IOException {
        String result = "user=>" + demoService.get(username) + " common movie have auth";
        response.getWriter().write(result);
        return username;
    }


    /**
     * URL:
     * /movie/adult?username=mother
     * /movie/adult?username=son
     *
     * @param request
     * @param response
     * @param username
     * @return
     */
    @LagouRequestMapping("/adult")
    @LagouSecurity(auths={"father","mother"})
    public String adult(HttpServletRequest request, HttpServletResponse response,String username) throws IOException {
        String result = "user=>" + demoService.get(username) + " adult movie have auth";
        response.getWriter().write(result);
        return username;
    }


    /**
     * URL:
     * /movie/adult?username=father
     * /movie/child?username=son
     *
     * @param request
     * @param response
     * @param username
     * @return
     */
    @LagouRequestMapping("/child")
    @LagouSecurity(auths={"son"})
    public String child(HttpServletRequest request, HttpServletResponse response,String username) throws IOException {
        String result = "user=>"+ demoService.get(username) + " child have auth";
        response.getWriter().write(result);
        return username;
    }
}
